#include "being.h"
#include <QGraphicsEllipseItem>
#include "hexitem.h"
#include <QPainter>
#include <cstdio>

Being::Being(QGraphicsEllipseItem *parent, double h) :
    QGraphicsEllipseItem(parent)
{
    maxSize = h;
    minSize = h/5;
    setFlags(QGraphicsItem::ItemIsFocusable  | QGraphicsItem::ItemIsSelectable);
    setAcceptsHoverEvents(true);
}

Being::Being(int T, int X, int Y, int SW, int MW, int W, int Speed, double h)
{
    typeOf = T;
    X = X;
    Y = Y;
    spawnW = SW;
    minW = MW;
    weight = W;
    speed = Speed;
    maxSize = h;
    minSize = h/5;
}

void Being::updateW(int Val)
{
    weight = Val;
}

double Being::updateSize()
{
    double displaySizeFactor = (maxSize - minSize) / (30000 - 1);
    double displaySizeConstant = maxSize - 30000 * displaySizeFactor;
    return weight * displaySizeFactor + displaySizeConstant;
}

void Being::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    update(boundingRect());
    //Q_UNUSED(option);
    //Q_UNUSED(widget);
    //painter->setPen(Qt::NoPen);
    //painter->setBrush(Qt::darkGray);
    //painter->drawEllipse(-12, -12, 30, 30);
    painter->setPen(QPen(Qt::blue, 0));
    if (typeOf)
    {
        painter->setBrush(QBrush(Qt::red));
        painter->setPen(QPen(Qt::red, 0));
    }
    else
    {
        painter->setBrush(QBrush(Qt::blue));
        painter->setPen(QPen(Qt::blue, 0));
    }
    double size = updateSize();
    painter->drawEllipse(-size, -size, size*2, size*2);
}


int Being::type() const
{
    return Type;
}

QRectF Being::boundingRect() const
{
    return QRectF(QPointF(-maxSize, - maxSize),QSizeF(maxSize*2, maxSize*2));
}
